package frontend.pages.worklog.monthly;

import backend.model.other.User;
import backend.service.other.UserService;
import frontend.core.TimeTrackingWebApplication;
import frontend.core.TimeTrackingWebSession;
import frontend.pages.base.BaseWebPage;
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.wicketstuff.annotation.mount.MountPath;

import static shared.other.UserRolesDefinition.ADMIN_ROLE_KEY;
import static shared.other.UserRolesDefinition.EMPLOYEE_ROLE_KEY;
import static shared.other.UserRolesDefinition.FOREMAN_ROLE_KEY;

@MountPath("monthlyWorkLog")
@AuthorizeInstantiation(value = {EMPLOYEE_ROLE_KEY, FOREMAN_ROLE_KEY, ADMIN_ROLE_KEY})
public class MonthlyWorkLogPage extends BaseWebPage {

    private MonthlyWorkLogPanel calendarPanel;

    public MonthlyWorkLogPage() {
        super("contextualHelp.monthlyWorkLogPage.text");

        String loggedInUsername = (String) TimeTrackingWebSession.get().getAttribute(TimeTrackingWebSession.LOGIN_USERNAME_ATTR);
        User loggedInUser = TimeTrackingWebApplication.getService(UserService.class).findUserByUsername(loggedInUsername);
        calendarPanel = new MonthlyWorkLogPanel("calendarPanel", loggedInUser.getEmployee());
        add(calendarPanel);
    }
}
